package timgmbh.monopoly.objects;

public class Player extends DatabaseObject {
	private User user;
	//private Field position;
	//private int gameId;
	
	public Player ()//Game game)
	{
		super("PLAYER","ID");
		
		user = new User();
		//position = null;
		//this.game = game;
	}
	
	public Player(int id) {//Game game, int id) {
		super("PLAYER","ID",id);
		
		//this.game = game;
		load(id);
	}
	
	public boolean load(int id)
	{
		user = new User();
		//game = new Game();
		
		boolean result = super.load(id);
		if (result == true) {
			result = user.load((int)getValue("USER"));
			//result = game.load((int)getValue("GAME"));
		}
		
		//gameId = (int)getValue("GAME");
		
		return result;
	}
	
	public boolean pay(int val) {
		if (getMoney() - val >= 0)
			return setMoney(getMoney() - val);
		else
			return false;
	}
	
	public void earn(int val) {
		setMoney(getMoney() + val);
	}
	
	public int getAvatar() {
		return (int)getValue("AVATAR");
	}
	public int getMoney() {
		return (int)getValue("MONEY");
	}
	public User getUser() {
		return user;
	}
	/*public int getGameId() {
		return gameId;
	}*/
	public int getPosition() {
		return (int)getValue("POSITION");
	}
	
	public boolean setAvatar(int val) {
		return setValue("AVATAR", val);
	}
	public boolean setMoney(int val) {
		return setValue("MONEY", val);
	}
	public boolean setUser(User val) {
		user = val;
		return setValue("USER", val.getID());
	}
	public boolean setGameId(int val) {
		//game = val;
		return setValue("GAME", val);
	}
	public boolean setPosition(int val) {
		return setValue("POSITION", val);
	}
	public void win() {
		getUser().win();
		getUser().save();
	}
}
